package com.study.service;
import com.study.dao.UserMapper;
import com.study.pojo.User;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImp implements  UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public boolean login(String username, String password) {
        if(username.isEmpty()||password.isEmpty()) return false;
        //调用Mapper得到密码
        String pwd = userMapper.login(username);
        //System.out.println("密码"+password);
//        if(pwd==null) return false;
        if(password.equals(pwd)) return true;
        return false;
    }

    @Override
    public int logon(String username,String password,String email,String gender,String telephone,String introduce) {
        return userMapper.logon(username, password,email,gender,telephone,introduce);
    }

    @Override
    public int updatePwd(String username, String old_password,String password) {
        String pwd = userMapper.login(username);
        System.out.println("原密码"+old_password);
        System.out.println("旧密码"+pwd);
        System.out.println("新密码"+password);
        if(old_password.equals(pwd)){
            int i = userMapper.updateUser(username, password);
            return i;
        }else{
            return 0;
        }
    }

    @Override
    public User getUser(String username) {
        return userMapper.getUser(username);
    }
}
